package org.pc2r.game.play;

import java.io.IOException;
import java.util.concurrent.Callable;

import org.pc2r.game.Game;
import org.pc2r.game.model.Player;
import org.pc2r.protocole.RequestBuilder;

public class RematchCallable implements Callable<Boolean> {

  private Player player;
  private Game game;
  
  public RematchCallable(Game game, Player player) {
    this.player = player;
    this.game = game;
  }

  @Override
  public Boolean call()  {
    try {
      String read = game.read(this.player.getName());
      if(RequestBuilder.isPlayerAgain(read)) {
        return Boolean.TRUE;
      }
    } catch (IOException exception) {
      // Si exception, on considère que c'est un bye
    }
    return Boolean.FALSE;
  }

}
